﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 信息文档查看记录 数据类
    /// </summary>
    public class DocReadLog
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DocReadLog()
        {
        }
        /// <summary>
        /// 是否已经存在阅读记录
        /// </summary>
        /// <param name="entityNo"></param>
        /// <param name="docId"></param>
        /// <param name="empNo"></param>
        /// <returns></returns>
        public bool Exists(string entityNo, decimal docId, string empNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId from t_docReadLog");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocId=@FDocId AND FEmplNo=@FEmplNo ");

            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)                    
                                        };
            parameters[0].Value = entityNo;
            parameters[1].Value = docId;
            parameters[2].Value = empNo;
            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.DocReadLog model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_docReadLog(");
            strSql.Append("FDocId,FReadTime,FIPAddr,FEmplNo,FDeptNo,FEntityNo,FNote,FDeptName,FEmpName)");
            strSql.Append(" values (");
            strSql.Append("@FDocId,@FReadTime,@FIPAddr,@FEmplNo,@FDeptNo,@FEntityNo,@FNote,@FDeptName,@FEmpName)");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
					new SqlParameter("@FReadTime", SqlDbType.DateTime),
					new SqlParameter("@FIPAddr", SqlDbType.NVarChar,20),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FNote", SqlDbType.Text),
					new SqlParameter("@FDeptName", SqlDbType.NVarChar,50),
					new SqlParameter("@FEmpName", SqlDbType.NVarChar,20)};
            parameters[0].Value = model.FDocId;
            parameters[1].Value = model.FReadTime;
            parameters[2].Value = model.FIPAddr;
            parameters[3].Value = model.FEmplNo;
            parameters[4].Value = model.FDeptNo;
            parameters[5].Value = model.FEntityNo;
            parameters[6].Value = model.FNote;
            parameters[7].Value = model.FDeptName;
            parameters[8].Value = model.FEmpName;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

        }
    }
}
